package com.yswy.backstage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yswy.backstage.service.DomainCertificateService;
import com.yswy.backstage.service.TgEventService;
import com.yswy.domain.entity.Domain;
import com.yswy.domain.entity.DomainCertificate;
import com.yswy.domain.entity.tf.TgEvent;
import com.yswy.domain.vo.dto.BaseFilter;
import com.yswy.domain.vo.gld.addOrUpate.DomainCertificateAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.TgEventAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.base.BaseReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/tgEvent")
@Api(tags = "回传事件管理")
public class TgEventController {

    @Autowired
    private TgEventService tgEventService;



    @PostMapping("/pageTgEvent")
    @ApiOperation(value = "回传事件列表")
    public Page<TgEvent> pageTgEvent(@RequestBody  BaseFilter req, HttpServletRequest request) {
        return tgEventService.pageTgEvent(req);
    }

    @GetMapping("/listTgEvent")
    @ApiOperation(value = "回传事件列表")
    public List<TgEvent> listTgEvent(@RequestParam(value = "tgEventId" , required = false) Long tgEventId,
                                   HttpServletRequest request) {
        return tgEventService.listTgEvent(tgEventId);
    }


    @GetMapping("/isExist")
    @ApiOperation(value = "判断事件是否存在")
    public Boolean isExist(@RequestParam(value = "identifier") String identifier,
                        HttpServletRequest request) {
        return tgEventService.isExist(identifier);
    }

    @PostMapping("/addTgEvent")
    @ApiOperation(value = "添加回传事件")
    public void addTgEvent(@RequestBody @Validated(BaseReqVO.CREATE.class) TgEventAddOrUpdate req, HttpServletRequest request) {
        tgEventService.addOrUpadteTgEvent(req);
    }

    @PostMapping("/upadteTgEvent")
    @ApiOperation(value = "修改回传事件")
    public void upadteTgEvent(@RequestBody @Validated(BaseReqVO.UPDATE.class) TgEventAddOrUpdate req, HttpServletRequest request) {
        tgEventService.addOrUpadteTgEvent(req);
    }

    @GetMapping("/delTgEvent")
    @ApiOperation(value = "删除回传事件")
    public void delTgEvent(@RequestParam(value = "tgEventId") Long tgEventId,
                                   HttpServletRequest request) {
        tgEventService.delTgEvent(tgEventId);
    }


}
